import count from '@dfeidao/atom-nodejs/db/count';
import operate from '@dfeidao/atom-nodejs/db/operate';
interface Message {
	_id: string;
	name: string;
	productid: string;
}
export default async function atom(msg: Message, action_id: string, session_id: string, spaceid: string) {
	const systemid = '12';
	const c = count(action_id, session_id, systemid);
	c.prepare('auth_formgroup', { productid: msg.productid, name: msg.name });
	const [t] = await c.exec();
	if (t > 0) {
		return 'other';
	}
	const { exec, update } = operate(action_id, session_id, systemid);
	update('auth_formgroup', { _id: msg._id, productid: msg.productid }, { name: msg.name });
	const res = await exec();
	if (res.code === 1) {
		return 'success';
	} else {
		return 'fail';
	}
}
